package org.lib.postgresqlhello.record.shard;

import org.lib.postgresqlhello.record.RecordCreateTableMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 * 用于启动器创建新表
 * @author ben
 * @date 2021-11-18 23:12:09 CST
 */
@Component
public class RecordRunner implements CommandLineRunner {

	@Autowired
	private RecordCreateTableMapper rctm;
	
	@Override
	public void run(String... args) throws Exception {
		createRecordTable();
	}
	
	/**
	 * 在数据库创建新表
	 * @author ben
	 * @date 2021-11-18 23:15:38 CST
	 */
	private void createRecordTable() {
		final String tableName = "tb_record";
		
		DateTableShardStrategy dtss = new DateTableShardStrategy();
		String newTableName = dtss.tableShard(tableName);
		
		rctm.createTable(newTableName);
	}

}
